package com.example.spldemo.spl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RequestMapping("/spl")
@RestController
public class SplController {
    @Autowired
    private UserInfoMapper mapper;
    // http://localhost:8087/spl/mybatistest
    @RequestMapping("/mybatistest")
    @ResponseBody
    public String execute() throws Exception {
        Map<String,Object> param=new HashMap<String, Object>();
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        calendar.set(1980, 6, 13);
        param.put("Date",calendar.getTime());
        List<UserInfo> userInfoList=  mapper.getUserWithParainfoList(param);
        for(UserInfo userInfo:userInfoList){
            System.out.println("查询的学生结果集: "+userInfo);
        }
        return userInfoList.toString();
    }
    //更加通用，返回map类型
    @RequestMapping("/mybatismap")
    // http://localhost:8087/spl/mybatisplustestmap
    @ResponseBody
    public String executemap() throws Exception {
        Map<String,Object> param=new HashMap<String, Object>();
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        calendar.set(1980, 6, 13);
        param.put("Date",calendar.getTime());
        List<Map<String,Object>> userInfoList=  mapper.getUserWithParainfomapList(param);
        for(Map<String, Object> map:userInfoList){
            System.out.println("查询的学生结果集: "+map);
        }
        return userInfoList.toString();
    }

}
